<?php

namespace Modules\Manager\Http\Controllers\Admin;

use App\Helpers\ResponseData;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Manager\Http\Requests\RoleRequest;
use Spatie\Permission\Models\Role;

class RoleController extends Controller
{
    use ResponseData;
    public function list()
    {
        $role = Role::query()
            ->select('id','zh_name','name')
            ->get();
        return $this->success($role);
    }

    public function store(RoleRequest $request)
    {
        $data = $request->all();
        $data['guard_name'] = 'sanctum';
        $role = Role::create($data);
        return $this->success($role);
    }

    public function edit(RoleRequest $request)
    {
        $data = Role::query()
            ->select('id','zh_name','name')
            ->find($request->id);
        return $this->success($data);
    }

    public function update(Request $request)
    {
        $data = $data = Role::query()->find($request->id);
        $data->update($request->all());
        return $this->success('更新成功');
    }
    public function destory(Request $request)
    {
        $data = $data = Role::query()->find($request->id);
        $data->delete();
        return $this->success('删除成功');
    }
}
